package com.main.by.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.main.by.dao.GeneralDao;
import com.main.by.dao.NewsInfoDao;
import com.main.by.entity.vo.NewsInfoVO;

@Repository
public class NewsInfoImpl implements NewsInfoDao {
	
	Logger logger = Logger.getLogger(this.getClass());
	
	@Autowired
	private GeneralDao generalDao;

	@Override
	public boolean insterNewsInfo(NewsInfoVO user) throws Exception {
		boolean successful = generalDao.saveEntity("insert into renren_news(newsTitle,mainKey,newsAuth,newsContent,newsDate,minPic,maxPic) values(?,?,?,?,?,?,?)", 
				new Object[]{user.getNewsTitle(),user.getMainKey(),user.getNewsAuth(),user.getNewsContent(),user.getNewsDate(),user.getMinPic(),user.getMaxPic()});
		return successful;
	}

	@Override
	public List<NewsInfoVO> findNews() throws Exception {
		return (List<NewsInfoVO>) generalDao.findAllEntity(NewsInfoVO.class, "select * from renren_news");
	}

	@Override
	public NewsInfoVO findNewsById(int newsId) throws Exception {
		return generalDao.getEntity(NewsInfoVO.class,new Object[]{newsId});
	}

	@Override
	public boolean deleteNewsById(int newsId) throws Exception {
		return generalDao.updateEntity("delete from renren_news where newsId=? ",new Object[]{newsId});
	}
	


}
